import sys
import pandas as pd
from pathlib import Path

CSV_PATH = Path('data/raw/TMDB_movie_dataset_v11.csv')

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print('Usage: python scripts/inspect_tmdb_row.py <tmdb_id>')
        sys.exit(1)
    tmdb_id = str(int(sys.argv[1]))
    if not CSV_PATH.exists():
        print('CSV not found:', CSV_PATH)
        sys.exit(2)

    found = None
    for chunk in pd.read_csv(CSV_PATH, chunksize=50000, low_memory=False, dtype=str):
        if 'id' not in chunk.columns:
            continue
        sub = chunk[chunk['id'].astype(str) == tmdb_id]
        if len(sub):
            found = sub.iloc[0].to_dict()
            break

    print('found?', found is not None)
    if found:
        all_cols = list(found.keys())
        print('columns_count', len(all_cols))
        print('columns', all_cols)
        keys = [k for k in all_cols if any(x in k.lower() for x in ['actor','cast','crew','director','credit','video','trailer','youtube','yt'])]
        print('interesting_keys', keys)
        for k in keys:
            v = found.get(k)
            if isinstance(v, str) and len(v) > 200:
                v_print = v[:200] + '...'
            else:
                v_print = v
            print(f'{k} => {v_print}')
